<template>
	<view>
		<cu-custom :bgcolor="'#fff'" />
		<view >
			<scroll-view v-if="shopList && shopList.length >0" scroll-y="true" :style="'height:'+scorllHeight+ 'px;'">
				<view class="shop-list">
					<view class="list-box pt-3 pb-3 pl-4 pr-4 mb-2" v-for="(item, index) in shopList" :key="index">
						<view class="list">
							<view class="list-center-info span-20 d-flex flex-column mt-2">
								<view class="d-flex flex-row  span-20" style="font-size: 26rpx;color: #999999;">
									<text class="mr-2 font-md">标题: {{item.title}}</text>
								</view>
								<view class="d-flex flex-row  span-20" style="font-size: 26rpx;color: #999999;">
									<text class="mr-2 font-md">审核状态: <text class="main-text-color">{{returnStatus(item.examine)}}</text></text>
								</view>
								<view class="d-flex flex-row" style="font-size: 26rpx;color: #999999;">
									<text class="flex-1 font-md">红包金额: {{item.money}}</text>
								</view>
								<view class="d-flex flex-row" style="font-size: 26rpx;color: #999999;">
									<text class="mr-2 font-md">优惠券金额承担: {{item.commitment_text}}</text>
								</view>
								<view class="d-flex flex-row span-20" style="font-size: 26rpx;color: #999999;">
									<text class="mr-2 font-md">使用条件: {{item.ava_text}}</text>
								</view>
								<view class="d-flex flex-row font-md span-20" style="font-size: 26rpx;color: #999999;">
									<text class="mr-2 font-md">使用有效期: {{item.start_time}} - {{item.end_time}}</text>
								</view>
								<view class="d-flex flex-row font-md span-20" style="font-size: 26rpx;color: #999999;">
									<text class="mr-2 font-md">是否在店铺领取: {{item.is_send_in_supplier == 0 ? '否' : '是'}}</text>
								</view>
								<view class="d-flex flex-row font-md span-20" style="font-size: 26rpx;color: #999999;">
									<text class="mr-2 font-md">是否与满减同享: {{item.is_coexist_manjian  == 0 ? '否' : '是'}}</text>
								</view>
							</view>
						</view>
						<view class="list-btn mt-3 d-flex flex-row a-center j-end">
							<button class="mini-btn m-0 mr-2 input-border-color border bg-none main-text-color"
								type="default" size="mini" @click.stop="toDelete(item.id)">删除</button>
							<!-- <button class="mini-btn m-0 mr-2 input-border-color border bg-none main-text-color"
								type="default" size="mini"
								@click.stop="redpacketStatus(item.id,item.status)">{{item.status == 0 ? '启用' : '禁用'}}</button> -->
							<!-- <button class="mini-btn m-0 main-bg-color text-white" type="default" size="mini"
								@click.stop="toDetail">编辑</button> -->
						</view>
					</view>

				</view>
				<!-- <view class="d-flex a-center j-center text-light-muted font-md py-3">{{loadtext}}</view> -->
			</scroll-view>
			
			<view v-else class="text-center mt-5">
				暂无数据
			</view>
			<view class="button-box p-2">
				<button class="main-bg-color text-white font-md" @click="addRed">新增</button>
			</view>
		</view>
		
	</view>
</template>

<script>
	import title from "@/components/common/title.vue"
	import divider from "@/components/common/divider.vue"
	import cuCustom from '@/components/common/custom.vue'
	import interceptor from "@/utils/request.js"
	export default {
		components: {
			title,
			divider,
			cuCustom
		},
		data() {
			return {
				value: 0,
				scorllHeight: 500,
				shopList: [],
				loadtext: "上拉加载更多",
				allChecked: false,
				formData: {
					idCard: "",
					name: ""
				}
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res => {
					this.scorllHeight = res.windowHeight - uni.upx2px(350)
				})
			})
		},
		onShow() {
			this.getRedpacketList()
		},
		methods: {
			addRed() {
				uni.navigateTo({
					url: './addCoupon'
				})
			},
			toDelete(id) {
				let _that = this
				uni.showModal({
					title: '确认删除?',
					success: function (res) {
						if (res.confirm) {
							interceptor.get('/supplier_applet_api.php?act=couponDel', {
								id
							}).then((res) => {
								if (res.status === 1) {
									uni.showToast({
										title: "删除成功",
										icon: "success",
										success() {
											_that.getRedpacketList()
										}
									})
								} else {
									uni.showToast({
										title: res.msg,
										icon: "error"
									})
								}
							})
						}
					}
				});
			},
			redpacketStatus(id, isShow) {
				let _that = this
				interceptor.get('/supplier_applet_api.php?act=redpacketStatus', {
					supplier_id: uni.getStorageSync('supplier_id'),
					id,
					status: isShow == 0 ? 1 : 0
				}).then((res) => {
					if (res.status === 1) {
						uni.showToast({
							title: "状态修改成功",
							icon: "success",
							success() {
								_that.getRedpacketList()
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: "error"
						})
					}
				})
			},
			getRedpacketList() {
				interceptor.get('/supplier_applet_api.php?act=couponList', {
					supplier_id: uni.getStorageSync('supplier_id')
				}).then((res) => {
					if (res.status === 1) {
						this.shopList = res.info.config_list
					} else {
						uni.showToast({
							title: res.msg,
							icon: "error"
						})
					}
				})
			},
			returnStatus(index){
				switch (index){
					case "0":
						return "待审核"
						break;
					case "1":
						return "审核通过"
						break;
					default:
						return "审核失败"
						break;
				}
			}

		}
	}
</script>

<style scoped lang="scss">
	.search-box {
		width: 100%;
		height: 160upx;
		background: #fff;

		box-sizing: border-box;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;

		.input {
			width: 90%;
			border-radius: 20px;
			overflow: hidden;
			border: 1px solid #BBBBBB;
			position: relative;

			.icon-sousuo {
				position: absolute;
				left: 35upx;
				top: 10upx;
			}

			.search {
				position: absolute;
				right: 40upx;
				top: 8upx;
			}
		}
	}

	.shop-list {
		background: #EBECED;
		height: auto;
		padding: 32rpx;
		box-sizing: border-box;

		.list-box {
			background: #FFFFFF;
			border-radius: 20rpx;
			height: auto;

			.list {
				height: auto;
				border-bottom: 1px dashed #dcdcdc;
			}

			.list-btn {}
		}

	}
</style>